package net.yunxinyong.cec.controller;

import net.sf.json.JSONObject;
import net.yunxinyong.cec.entity.Cec711BaseSituation;
import net.yunxinyong.cec.mapper.Cec711BaseSituationMapper;
import net.yunxinyong.cec.service.Cec711BaseService;
import net.yunxinyong.cec.utils.CECResult;
import net.yunxinyong.cec.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 李跃
 * @date 2018/9/17
 */
@RequestMapping("/711base")
@RestController
public class Cec711BaseController {
    @Autowired
    private Cec711BaseService cec711BaseService;
    @Autowired
    private Cec711BaseSituationMapper cec711BaseSituationMapper;
    /**
     * 查询所有基础信息
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping(value = "getAll/{page}/{rows}",method = RequestMethod.POST)
    public CECResult getAllBaseInformatin(@PathVariable int page, @PathVariable int rows, @RequestBody Cec711BaseSituation cec711BaseSituation){
        PageBean pageBean = cec711BaseService.ListAll(page, rows,cec711BaseSituation);
        return     CECResult.build(200,pageBean);
    }
    /**
     * 添加企业基础
     */
    @RequestMapping("add")
    public CECResult insertBaseinformation(@RequestBody Cec711BaseSituation cec711BaseSituation){
        JSONObject jsonObject = JSONObject.fromObject(cec711BaseSituation);
        Cec711BaseSituation o = (Cec711BaseSituation)JSONObject.toBean(jsonObject, Cec711BaseSituation.class);
        System.out.println("进入方法");
        Cec711BaseSituation cec711BaseSituation1 = cec711BaseService.insertBase(o);
        if(cec711BaseSituation1 == null){
            return CECResult.build(500,"企业基础信息已存在");
        }
        return CECResult.build(200,"企业基础信息添加成功",cec711BaseSituation1);
    }



    /**
     * 删除企业信息
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public CECResult deleteBase(@RequestParam(value = "id") Integer id){
        int i = cec711BaseService.deleteBase(id);
        if(i > 0){
            return CECResult.build(200,"企业信息删除成功");
        }
        return CECResult.build(500,"企业信息删除失败");
    }
    @RequestMapping("update")
    public CECResult updateBase(@RequestBody Cec711BaseSituation cec711BaseSituation){
        int i = cec711BaseService.updateBase(cec711BaseSituation);
        if(i > 0){
            return CECResult.build(200,"企业信息修改成功");
        }
        return CECResult.build(500,"企业信息修改失败");
    }


    /**
     *
     * @return
     */
    @RequestMapping("test")
    public String test(){
        Cec711BaseSituation cec711BaseSituation = new Cec711BaseSituation();
        cec711BaseSituation.setId(2);
        cec711BaseSituation.setStatus(88888888);
        System.out.println("qqqqqqqqqqqqq");
        System.out.println("wwwwwwwwwwwwwwwwwww");
        System.out.println("eeeeeeeeeeeeee");
        System.out.println("rrrrrrrrrrrrrrrrrrrrr");
        int i = cec711BaseSituationMapper.updateByPrimaryKeySelective(cec711BaseSituation);
        if(i==0){
            System.out.println("企业信息删除失败");
            return "企业信息删除失败";
        }
        System.out.println("成功删除企业");
        return "heel"+i;
    }


}
